package com.tumblr.anond2.solr.client.solrj;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * SolrKVSClient CLI.
 * <p>$ java -Dlog4j.configuration=file:///path/to/dir/solrsimpleclient/lib/log4j.properties -cp solrsimpleclient-X.X-Y.Y.jar:lib/* com.tumblr.anond2.solr.client.solrj.SolrKVSClientCLI put 1 abc</p>
 * <p>$ java -Dlog4j.configuration=file:///path/to/dir/solrsimpleclient/lib/log4j.properties -cp solrsimpleclient-X.X-Y.Y.jar:lib/* com.tumblr.anond2.solr.client.solrj.SolrKVSClientCLI get 1</p>
 * <p>$ java -Dlog4j.configuration=file:///path/to/dir/solrsimpleclient/lib/log4j.properties -cp solrsimpleclient-X.X-Y.Y.jar:lib/* com.tumblr.anond2.solr.client.solrj.SolrKVSClientCLI remove 1</p>
 */
public class SolrKVSClientCLI {

	public SolrKVSClientCLI() {

	}

	public static void main(String[] args) throws Exception {
		SolrConnection cnn = new SolrConnection(checkNotNull(System.getProperty("url"), "url param is required"));
		cnn.open();

		SolrKVSClient client = SolrKVSClient.getInstance();
		
		if (args[0].equals("put")){
			client.put(args[1], args[2]);
			System.out.println("success:" + args[1]);
			return;
		}

		if (args[0].equals("get")){
			System.out.println(client.get(args[1]));
			return;
		}

		if (args[0].equals("remove")){
			client.remove(args[1]);
			System.out.println("success:" + args[1]);
			return;
		}

		System.err.println("Usage: SolrKVSClientCLI [put <key> <value>] [get <key>] [remove <key>]");
		System.exit(1);

	}

}
